package com.lkd.controller;

import com.lkd.dto.PartnerDTO;
import com.lkd.entity.Partner;
import com.lkd.mapper.PartnerMapper;
import com.lkd.result.TableInfo;
import com.lkd.service.PartnerService;
import com.lkd.vo.PartnerVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: Z.lx
 * @Date: 2025/8/17 11:06
 * @Description:
 **/
@RestController
@RequestMapping("/api/user-service/partner")
@Slf4j
public class PartnerController {
    private final PartnerService partnerService;
    @Autowired
    public PartnerController(PartnerService partnerService) {
        this.partnerService = partnerService;
    }
    /**
    * @Description 新增合作商
    * @Param [partnerDto]
    * @Date 2025/8/17 11:24
    **/
    @PostMapping
    public boolean save(@RequestBody PartnerDTO partnerDto){
        log.info("新增合作商:{}",partnerDto);
        partnerService.save(partnerDto);
        return true;
    }
    /**
    * @Description 列表查询
    * @Param [partnerDto]
    * @Date 2025/8/17 11:26
    **/
    @GetMapping("/search")
    public TableInfo<Partner> list(PartnerDTO partnerDto){
        log.info("查询合作商:{}",partnerDto);
        return partnerService.list(partnerDto);
    }
    /**
    * @Description 查询详情
    * @Param [partnerId]
    * @Date 2025/8/17 11:34
    **/
    @GetMapping("/{id}")
    public PartnerVO info(String id){
        log.info("查询合作商ID详情:{}",id);
        return partnerService.partnerId(id);
    }
    /**
    * @Description 修改信息
    * @Param [id, partnerDto]
    * @Date 2025/8/17 11:48
    **/
    @PutMapping("/{id}")
    public boolean update(@PathVariable String id,@RequestBody PartnerDTO partnerDto){
        log.info("更新合作商信息:{}",partnerDto);
        partnerDto.setId(id);
        return partnerService.update(partnerDto);
    }
    /**
    * @Description 删除合作商
    * @Param [id]
    * @Date 2025/8/17 11:48
    **/
    @DeleteMapping("/{id}")
    public boolean delete(@PathVariable String id){
        log.info("删除合作商:{}",id);
        return partnerService.delete(id);
    }
    /**
    * @Description 重置密码
    * @Param [id]
    * @Date 2025/8/17 11:48
    **/
    @PutMapping("/resetPwd/{id}")
    public boolean resetPwd(@PathVariable String id){
        log.info("重置合作商密码:{}",id);
        return partnerService.resetPwd(id);
    }

    /**
    * @Description 获取合作商数量
    * @Param []
    * @Date 2025/8/17 11:48
    **/
    @GetMapping("/count")
    public Integer countPartner(){
        return partnerService.count();
    }
}
